package ar.com.spsolutions.splilabrary.view.pages.book;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import ar.com.spsolutions.splibrary.book.BookComment;

public class Page extends WebPage {

    private static final long serialVersionUID = -3486873071572550722L;

    private List<BookComment> comments;

    public Page(final List<BookComment> comments) {
        super();
        this.comments = comments;

        addNewComment();
        addComments();
    }

    private void addNewComment() {
        final Form<BookComment> formComment = new Form<BookComment>("formComment") {

            private static final long serialVersionUID = 8013145781615086654L;

            @Override
            protected void onSubmit() {
                // stub

            }
        };
        formComment.add(new TextArea<String>("newComment"));
        this.add(formComment);
    }

    private void addComments() {
        final ListView<BookComment> list = new ListView<BookComment>("commentPanel", getComments()) {

            private static final long serialVersionUID = 3634224977916608964L;

            @Override
            protected void populateItem(final ListItem<BookComment> item) {
                final BookCommentPanel bookDetail = new BookCommentPanel("bookCommentPanel", item.getModelObject());
                item.add(bookDetail);
            }
        };
        this.add(list);
    }

    public List<BookComment> getComments() {
        return comments;
    }

    public void setComments(final List<BookComment> comments) {
        this.comments = comments;
    }

}
